package com.atguigu.gmall.product.service.impl;

import com.atguigu.gmall.product.mapper.SkuAttrValueMapper;
import com.atguigu.gmall.product.mapper.SkuInfoMapper;
import com.atguigu.gmall.product.model.BaseAttrInfo;
import com.atguigu.gmall.product.model.SkuInfo;
import com.atguigu.gmall.product.service.SkuInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * 库存单元表 业务实现类
 *
 * @author atguigu
 * @since 2023-04-20
 */
@SuppressWarnings("all")
@Service
public class SkuInfoServiceImpl extends ServiceImpl<SkuInfoMapper, SkuInfo> implements SkuInfoService {
    @Autowired
    private SkuAttrValueMapper skuAttrValueMapper;

    /**
     * 根据spuId获取当前平台属性和平台属性值
     * @param attrId
     * @return
     */
    @Override
    public List<BaseAttrInfo> getAttrList(Long skuId) {
        //1.调用持久层对象调用持久层自定义sql

        List<BaseAttrInfo> list = skuAttrValueMapper.getAttrList(skuId);
        if(!CollectionUtils.isEmpty(list)){
            for (BaseAttrInfo baseAttrInfo:list){
                baseAttrInfo.setAttrValue(baseAttrInfo.getAttrValueList().get(0).getValueName());
            }
        }
        return list;
    }
}
